#!/bin/bash

# 批量生成summary脚本

# 获取所有没有summary的demand_id
mysql -h 47.92.162.251 -P 3306 -u remote_user -pliYC060214pp expert_miniapp_db -sN -e "SELECT demand_id FROM demand WHERE summary IS NULL OR summary = '';" > /tmp/demand_ids.txt

# 统计总数
total=$(wc -l < /tmp/demand_ids.txt)
count=0

echo "开始批量生成summary,共 $total 个需求"

# 逐个调用API生成summary
while IFS= read -r demand_id; do
  count=$((count+1))
  echo "[$count/$total] 正在生成: $demand_id"

  curl -X POST "http://localhost:8080/api/demands/$demand_id/regenerate-summary" \
    -H "Content-Type: application/json" \
    -s -o /dev/null -w "Status: %{http_code}\n"

  # 避免请求过快
  sleep 2
done < /tmp/demand_ids.txt

echo "批量生成完成!"
